﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ClientAppViaWebService.Navigators
{
    public partial class ObjectSelectionNavigatorForm : Form
    {
        public List<int> SearchingClassIdsList { get; set; }
        public string SelectedObjectName { get; set; }
        public string SelectedObjectExtId{ get; set; }
        public enum SelectModes  { FILTERED_MODE , FULL_MODE };
        public SelectModes SelectedMode = SelectModes.FULL_MODE;

        public ObjectSelectionNavigatorForm()
        {
            InitializeComponent();           
            baseNavigator.uniTreeView.NodeMouseClick += new TreeNodeMouseClickEventHandler(uniTreeView_NodeMouseClick);
                 
        }

        void uniTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            btnSelect.Enabled = baseNavigator.ActiveNode == null  ? false
                : SearchingClassIdsList.Contains(baseNavigator.ActiveNode.CLASS_ID);
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {
            SelectedObjectName = baseNavigator.ActiveNode == null ? String.Empty : baseNavigator.ActiveNode.NAME;
            SelectedObjectExtId = baseNavigator.ActiveNode == null ? String.Empty
                     : baseNavigator.ActiveNode.EXT_ID;
        }

        public void LoadSearchingNavigator(string extId, List<int> serchingClassIdsList)
        {
            ///Here will be recursive expanding of current selectedItem
            ///if  it's not selected already - only University node expands.

            //if (extId == String.Empty) baseNavigator.LoadNavigator("0");
            //else baseNavigator.LoadNavigatorForSelectedNode(extId);

            SelectedMode = SelectModes.FULL_MODE;
            baseNavigator.LoadNavigator("0");
            SearchingClassIdsList = serchingClassIdsList;
        }

        private void btnSwitchSelectMode_Click(object sender, EventArgs e)
        {
            if (SelectedMode == SelectModes.FULL_MODE) SelectedMode = SelectModes.FILTERED_MODE;
            else if (SelectedMode == SelectModes.FILTERED_MODE) SelectedMode = SelectModes.FULL_MODE;

            switch (SelectedMode)
            {
                case SelectModes.FULL_MODE: baseNavigator.LoadNavigator("0"); break;
                case SelectModes.FILTERED_MODE: baseNavigator.LoadNavigatorFilteredByClassIds(SearchingClassIdsList.ToArray()); break;
            }
        }
                          
    }
}
